Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / feature / node / src / main / kotlin / org / meshtastic / feature / node / metrics / HardwareModelExtensions.kt

Displaying Raw • Download

feature/node/src/main/kotlin/org/meshtastic/feature/node/metrics/HardwareModelExtensions.kt 78274c792318331b11ab64cd28e58e829875b8c2 (78274c79) Text, 1.62 KB

T8b949e/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

Tff7b72package T7ee787org.meshtastic.feature.node.metrics

Tff7b72import T7ee787org.meshtastic.proto.MeshProtos
Tff7b72import T7ee787timber.log.Timber

T8b949e/**
* Safely extracts the hardware model number from a HardwareModel enum.
*
* This function handles unknown enum values gracefully by catching IllegalArgumentException and returning a fallback
* value. This prevents crashes when the app receives data from devices with hardware models not yet defined in the
* current protobuf version.
*
* @param fallbackValue The value to return if the enum is unknown (defaults to 0 for UNSET)
* @return The hardware model number, or the fallback value if the enum is unknown
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffdetekt:SwallowedExceptionTa5d6ff"Tb4b4b4)
Tff7b72fun Te6edf3MeshProtosTb4b4b4.Td2a8ffHardwareModelTb4b4b4.Te6edf3safeNumberTb4b4b4(Te6edf3fallbackValueTb4b4b4: Tffa657Int Tff7b72= Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4: Tffa657Int Tff7b72= Tff7b72try Tb4b4b4{
Tff7b72thisTb4b4b4.Te6edf3number
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3IllegalArgumentExceptionTb4b4b4) Tb4b4b4{
Te6edf3TimberTb4b4b4.Te6edf3wTb4b4b4(Ta5d6ff"Ta5d6ffUnknown hardware model enum value: Tffd700$Te6edf3thisTa5d6ff, using fallback value: Tffd700$Te6edf3fallbackValueTa5d6ff"Tb4b4b4)
Te6edf3fallbackValue
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s